#define _DATA_FLASH_C_
/* Includes ---------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "dataflash.h"
/* USER CODE END Includes */

/* Macro ------------------------------------------------------------*/
/* USER CODE BEGIN Macro */
#define DATA_FLASH_VERSION                                      (0x02)

#define DATA_FLASH_START_ADDR                                   (0x0001C000UL)
#define DATA_FLASH_END_ADDR                                     (0x0001FFFFUL)

#define PAGE_SIZE                                               (512)

#define DATA_FLASH_PAGE0                                        (DATA_FLASH_START_ADDR)
#define DATA_FLASH_PAGE1                                        (DATA_FLASH_PAGE0 + PAGE_SIZE)
#define DATA_FLASH_PAGE2                                        (DATA_FLASH_PAGE1 + PAGE_SIZE)
#define DATA_FLASH_PAGE3                                        (DATA_FLASH_PAGE2 + PAGE_SIZE)

/* USER CODE END Macro */

/* Types ------------------------------------------------------------*/
/* USER CODE BEGIN Types */
// Must be four-byte aligned
enum DataFlashMap
{
	eDATAFLASH_UNIT = DATA_FLASH_START_ADDR,
	eDATAFLASH_RANGE,
	// reserved[2]
	
	eDATAFLASH_DAC_4mA_CALI = eDATAFLASH_UNIT + 4,
	eDATAFLASH_DAC_20mA_CALI = eDATAFLASH_DAC_4mA_CALI + 4,
	
	eDATAFLASH_SENSOR_ZERO = eDATAFLASH_DAC_20mA_CALI + 4,
	eDATAFLASH_SENSOR_FULL = eDATAFLASH_SENSOR_ZERO + 4,
};
/* USER CODE END Types */

/* Constants --------------------------------------------------------*/
/* USER CODE BEGIN Constants */

/* USER CODE END Constants */

/* Variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */
//STSystemData stSysData;
//STSystemData stSysShowData;

//STSystemData stSysDataDefault = 
//{
//	
//};
/* USER CODE END Variables */

/* Function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FP */

/* USER CODE END FP */

/**
  * @brief  LPTIM Initialization function
  * @param  void
  * @retval None
  */
void vDataFlashPowerOnLoadData(void)
{

}



/**
  * @brief  Save modified data.
  * @param  void
  * @retval None
  */
void vDataFlashSaveModifiedData(void)
{
//	FL_FLASH_PageErase(FLASH, DATA_FLASH_PAGE0);
//	
//	for(uint8_t i = 0; i < (sizeof(stSysData) / 4); i++)
//	{
//		FL_FLASH_Program_Word(FLASH, DATA_FLASH_START_ADDR + (4 * i), *((uint32_t *)(((uint8_t *)&stSysData) + 4 * i)));
//	}
}

/**
  * @brief  Setup
  * @param  void
  * @retval None
  */
void vDataFlashSetupOp(void)
{
//	FL_FLASH_PageErase(FLASH, DATA_FLASH_PAGE0);
//	
//	for(uint8_t i = 0; i < (sizeof(stSysDataDefault) / 4); i++)
//	{
//		FL_FLASH_Program_Word(FLASH, DATA_FLASH_START_ADDR + (4 * i), *((uint32_t *)(((uint8_t *)&stSysDataDefault) + 4 * i)));
//	}
//	memcpy((uint8_t *)&stSysData, (uint8_t *)&stSysDataDefault, sizeof(stSysDataDefault));
//	memcpy((uint8_t *)&stSysShowData, (uint8_t *)&stSysDataDefault, sizeof(stSysDataDefault));
}
